﻿using Chart3D;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CloundModelPrj
{
    public partial class Chart3D : Form
    {
        /// <summary>
        /// 三维绘图
        /// </summary>
        private Chart3DMain chart3D { set; get; }

        /// <summary>
        /// 模型显示
        /// </summary>
        /// <param name="singleModel"></param>
        public static void ShowModel(SingleModel singleModel)
        {
            var model = new Chart3D(singleModel, true);
            model.ShowDialog();
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        public Chart3D(SingleModel singleModel, bool isBlack)
        {
            InitializeComponent();

            #region 绘三维图时启用
            this.SetStyle(ControlStyles.ResizeRedraw, true);
            //When this flag is set to true,
            //the control paints itself and is not painted by the system operation
            this.SetStyle(ControlStyles.UserPaint, true);
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            //when set Control.DoubleBuffered to true, 
            //it will set the ControlStyles.AllPaintingInWmPaint and ControlStyles.OptimizedDoubleBuffer to true    
            this.SetStyle(ControlStyles.DoubleBuffer, true);
            #endregion

            //修改背景色
            this.PlotPanel.BackColor = isBlack ? Color.Black : Color.White;
            //测试：获得PM分析结果
            this.chart3D = singleModel.GetChart3DMain(this.PlotPanel);
            //绘图
            this.RefreshBackground();
        }

        /// <summary>
        /// 重新绘图，更新图片
        /// </summary>
        private void RefreshBackground()
        {
            if (this.chart3D == null) return;
            //绘图
            this.chart3D.ToGraphics(this.trkElevation.Value, this.trkAzimuth.Value, isAixsToG: false);
        }

        /// <summary>
        /// 旋转
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RotaButton_Click(object sender, EventArgs e)
        {
           this.chart3D.ToRotationGraphics(this.Cursor, isAixsToG: false);
        }

        private void trkElevation_Scroll(object sender, EventArgs e)
        {
            tbElevation.Text = trkElevation.Value.ToString();
            this.RefreshBackground();
        }

        private void trkAzimuth_Scroll(object sender, EventArgs e)
        {
            tbAzimuth.Text = trkAzimuth.Value.ToString();
            this.RefreshBackground();
        }

        private void PlotPanel_Resize(object sender, EventArgs e)
        {
            this.RefreshBackground();
        }
    }
}
